package project3.datasets;

import java.util.Arrays;

/**
 * An instance represents a row.
 * 
 * @author Antonio
 * @author Vika
 */
public class Instance implements Cloneable {
	private static final long serialVersionUID = 1L;

	/** Row values encoded in doubles */
	private double[] values;

	/**
	 * Constructs a new <code>Instance</code>.
	 * 
	 * @param values
	 *            array of encoded values
	 */
	public Instance(double[] values) {
		this.values = values.clone();
	}

	@Override
	public String toString() {
		return "Instance [values=" + Arrays.toString(values) + "]";
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Instance) {
			Instance other = (Instance) obj;
			return Arrays.equals(this.values, other.values);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return Arrays.hashCode(this.values);
	}

	/**
	 * @return Returns the values.
	 */
	public double[] getValues() {
		return values;
	}

	/**
	 * @param values
	 *            The values to set.
	 */
	public void setValues(double[] values) {
		this.values = values;
	}

	public void setValueAt(int idx, double value) {
		this.values[idx] = value;
	}

	public double getValueAt(int idx) {
		return this.values[idx];
	}

	@Override
	public Instance clone() {
		Instance clone = null;
		try {
			clone = (Instance) super.clone();
			clone.values = this.values.clone();
		} catch (CloneNotSupportedException e) {
			throw new Error(e);
		}
		return clone;
	}

}
